<?php include  APP_PATH.'../template/public/header.php'?>
    <aside class="main-sidebar">
        <section class="sidebar">
            <?php include APP_PATH.'../template/public/navigation.php'?>
        </section>
    </aside>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                {$title}
                <a href="{:url('add_advertisers')}" class="btn  btn-primary ">新增广告主</a>
            </h1>

            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> {$title}</a></li>
            </ol>
        </section>
        <section class="content">
            <div class="row">
                <div class="col-md-12">
                    <div class="box">
                        <div class="box-body">
                            <table id='table'
                                   data-url=""
                                   data-toggle="table"
                                   data-show-refresh="true"
                                   data-show-toggle="true"
                                   data-show-columns="true"
                                   data-search="true"
                                   data-ajax="ajax_request"
                                   data-advanced-search="true"
                                   data-pagination="true"
                                   data-side-pagination="server"
                                   data-page-list="[5, 10, 15, 20, 30, 50]"
                                   data-select-item-name="worker_picker"
                                   data-show-export="true"
                                   data-click-to-select="true"
                                   data-toolbar="#toolbar"
                                   data-sort-name="name"
                                   data-sort-order="desc">
                                <div class="bars pull-left">
                                </div>
                                <thead>
                                <tr>
                                    <th data-field="id"   data-align="left" data-sortable="true"  >账户ID</th>
                                    <th data-field="name"  data-align="left" data-sortable="true"  >广告主账户名</th>
                                    <th data-field="advertisers_name"   data-align="left" data-sortable="true" >广告主名称</th>
                                    <th data-field="industry"   data-align="left" data-sortable="true" >行业分类</th>
                                    <th data-field=""   data-align="left" data-sortable="true" >余额</th>
                                    <th data-field=""   data-align="left" data-sortable="true" >优惠券</th>
                                    <th data-field=""   data-align="left" data-sortable="true" >昨日消费</th>
                                    <th data-field=""   data-align="left" data-sortable="true" >今日消费</th>
                                    <th data-field=""   data-align="left" data-sortable="true" >余额可消耗天数</th>
                                    <th data-field="attr_user_rname"   data-align="left" data-sortable="true" >所属子账户</th>
                                    <th data-field=""   data-align="left" data-sortable="true" >状态</th>
                                    <th data-field=""   data-align="left" data-sortable="true" >开户日期</th>
                                    <th data-field=""   data-align="left" data-sortable="true" >拒绝原因</th>
                                    <th data-field="time"   data-align="left">更新时间</th>
                                    <th data-field="operate">操作</th>
                                </tr>

                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                        </div>
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div>
        </section>
        <div class="modal fade bs-example-modal-sm" id='edit_worker'>
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">账户充值</h4>
                    </div>
                    <div class="modal-body">
                        <form id="form1">
                            <!-- text input -->
                            <div class="form-group">
                                <input type="hidden" class="form-control" name='user_id' id='user_id'/>
                                <input type="hidden" class="form-control" name='operation_user_id' id='operation_user_id'/>
                                <label>用户名</label>
                                <input type="text" class="form-control" name='username' id='username' disabled/>
                            </div>
                            <div class="form-group">
                                <label>当前余额</label>
                                <input type="text" class="form-control"  id='amount' disabled/>
                            </div>
                            <div class="form-group">
                                <label>充值金额</label>
                                <input type="text" class="form-control" name='recharge_amount' id='recharge_amount' value="0"/>
                            </div>
                            <div class="form-group">
                                <label>充值方式</label>
                                <select class="form-control" name='recharge_type' id='recharge_type'>
                                    <option value='3' selected="selected">支付宝</option>
                                    <option value='4' selected="selected">微信</option>
                                    <option value='5' selected="selected">转账</option>
                                </select>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                                <button  type="button" id="submit_updata" class="btn btn-primary" >充值</button>
                            </div>
                        </form>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
    </div>
<?php include APP_PATH.'../template/public/footer.php'; ?>
<script>
    function ajax_request(params) {
        var parameter_str = jQuery.param( params.data );
        $.get("{:url('admin/advertisers/get_advlist')}?"+parameter_str, function(data){
            // alert(data);
            eval("data="+data);
            // alert(data);
            params.success(data);
        });
    }
    function  reset_pwd(id) {
        $.get("{:url('admin/Manageuser/reset_pwd')}?user_id="+id,function (res) {
            if (res.code > 0) {
                layer.open({
                    type: 1
                    ,offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                    ,id: 'layerDemoauto' //防止重复弹出
                    ,content: '<div style="padding: 20px 100px;">'+res.msg+'</div>'
                    ,btn: '关闭'
                    ,btnAlign: 'c' //按钮居中
                    ,shade: 0 //不显示遮罩
                    ,yes: function(){
                        layer.closeAll();
                    }
                });
            } else {
                layer.open({
                    type: 1
                    ,offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                    ,id: 'layerDemoaoto1' //防止重复弹出
                    ,content: '<div style="padding: 20px 100px;">'+res.msg+'</div>'
                    ,btn: '关闭'
                    ,btnAlign: 'c' //按钮居中
                    ,shade: 0 //不显示遮罩
                    ,yes: function(){
                        layer.closeAll();
                    }
                });
            }
        });
    }
    function  recharge(id) {
        $.get('{:url("get_user_amount")}',{user_id:id},function (res) {
            if(res.code>0){
                $("#edit_worker input").val('');
                $('#amount').val(res.amount.cash_balance);
                $('#user_id').val(res.amount.user_id);
                $('#operation_user_id').val(res.user.id);
                $('#username').val(res.amount.username);
                $("#edit_worker").modal('show');
            }else {
                return false;
            }
        });
    }
    $("#recharge_amount").keyup(function() {
        var regStrs = [
            ['^0(\\d+)$', '$1'], //禁止录入整数部分两位以上，但首位为0
            ['[^\\d\\.]+$', ''], //禁止录入任何非数字和点
            ['\\.(\\d?)\\.+', '.$1'], //禁止录入两个以上的点
            ['^(\\d+\\.\\d{2}).+', '$1'] //禁止录入小数点后两位以上
        ];
        var testNum = $(this).val();
        if (testNum) {
            for (i = 0; i < regStrs.length; i++) {
                var reg = new RegExp(regStrs[i][0]);
                if (reg.test(testNum)) {
                    layer.msg('输入金额有误',{time: 1800, icon: 2});
                    $(this).val('');
                }
            }
        }
    });
    $('#submit_updata').click(function () {
        var data = {};
        var t = $('#form1').serializeArray();
        $.each(t, function() {
            data[this.name] = this.value;
        });
        data[$('#username').attr('name')] =$('#username').val();
        $.post('{:url("recharge")}',data,function (res) {
            if(res.code>0){
                layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                    $("#edit_worker").modal('hide');
                    $('#table').bootstrapTable('refresh');
                });
            }else {
                layer.msg(res.msg, {time: 1800, icon: 2});

            }
        });
    });
</script>
</html>